# @Time : 2020/7/30 11:05
# @Author : Fioman 
# @Phone : 13149920693
import cv2 as cv
import numpy as np

"""
计算三幅图像的Hu矩,并进行比较.
"""
img1 = cv.imread("cs1.bmp")
gray1 = cv.cvtColor(img1,cv.COLOR_BGR2GRAY)
img2 = cv.imread("cs2.bmp")
gray2 = cv.cvtColor(img2,cv.COLOR_BGR2GRAY)
img3 = cv.imread("lena.bmp")
gray3 = cv.cvtColor(img3,cv.COLOR_BGR2GRAY)


huM1 = cv.HuMoments(cv.moments(gray1)).flatten()
huM2 = cv.HuMoments(cv.moments(gray2)).flatten()
huM3 = cv.HuMoments(cv.moments(gray3)).flatten()

print("img1.shape = {}".format(img1.shape))
print("img2.shape = {}".format(img2.shape))
print("img3.shape = {}".format(img3.shape))

print("cv.moments(gray1) = \n{}".format(cv.moments(gray1)))
print("cv.moments(gray2) = \n{}".format(cv.moments(gray2)))
print("cv.moments(gray3) = \n{}".format(cv.moments(gray3)))

print("HuM1 = \n {}".format(huM1))
print("HuM2 = \n {}".format(huM2))
print("HuM3 = \n {}".format(huM3))

# 计算图像img1与图像img2,图像img3的Hu矩之差

print("HuM1 - HuM2 = {}".format(huM1 - huM2))
print("HuM2 - HuM3 = {}".format(huM2 - huM3))

# 显示图像
cv.imshow("Original1",img1)
cv.imshow("Original2",img2)
cv.imshow("Original3",img3)
cv.waitKey(0)
cv.destroyAllWindows()